<?php

class Core_Model_DbTable_DunnageDocuments extends Zend_Db_Table_Abstract {
    
    protected $_name = 'dunnage_documents';
    
    public function getDunnageDocument($id = -1){
         if($id == -1){
             return null;
         }

        $cond = $this->getAdapter()->quoteInto("dunnage_id = (?)", $id);
        $docs = $this->fetchAll($cond)->toArray();
        foreach ($docs as &$doc) {
            $splits = explode("/", $doc['file']);
            $file_name = end($splits);
            $doc['file_name'] = $file_name;
            $splits_type = explode(".", $file_name);
            $file_extension = end($splits_type);
            switch ($file_extension) {
                case 'jpg': 
                case 'png':
                case 'gif':
                    $doc['file_type'] = 'bmp';
                    break;
                case 'xlsx':
                case 'xls':
                    $doc['file_type'] = 'excel';
                    break;
                case 'pdf': 
                    $doc['file_type'] = 'pdf';
                    break;
                default: 
                    $doc['file_type'] = 'word';
                    break;
            }
        }
        return $docs;
    }
}
?>
